<template>
    <teleport to='body'>
      <transition name="fade">
        <div class="Mask" v-show="showDialog">
          <div class="Dialog" :style="`height: ${height};width: ${width};`">
            <div class="DialogTitle">
              <slot name="header"></slot>
              <div>
                <div class="littleClose" @click="closeDialog">×</div>
              </div>
            </div>
            <el-divider></el-divider>
            <slot></slot>
          </div>
        </div>
      </transition>
    </teleport>
</template>

<script>
import { useStore } from "vuex";

export default {
  name: "Dialog",
  props: ["showDialog", "width", "height"],
  emits: ["update:showDialog"],
  setup(props, emits) {
    let store = useStore();
    let width = "30%";
    let height = "auto";
    if (props.width !== undefined)
      width = props.width;
    if (props.height !== undefined)
      height = props.height

    function closeDialog() {
      emits.emit("update:showDialog", false);
    }

    return {
      closeDialog,
      height,
      width
    };
  },
};
</script>

<style lang="css" scoped>
.Mask {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  backdrop-filter: var(--backFilter);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 101;
  transition: all 0.3s linear;
  -moz-transition: all 0.3s linear;
  -webkit-transition: all 0.3s linear;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
.fade-enter-to,
.fade-leave-from {
  opacity: 1;
}
.fade-enter-active,
.fade-leave-active {
  transition: 0.5s;
  -moz-transition: 0.5s;
  -webkit-transition: 0.5s;
}

.Dialog {
  background-color: rgba(250, 250, 250, 0.7);
  border-radius: 1.2em;
  padding: 20px;
  box-shadow: 0px 0px 10px 2px rgba(160, 160, 160, 0.6);
}

.DialogTitle {
  display:flex;
  justify-content: space-between;
}

.littleClose {
  border-radius: .3em;
  background-color: var(--mainColor);
  color: white;
  cursor: pointer;
  padding:0 7px;
}

.littleClose {
  color: var(--mainColor);
  padding: 0 10px;
  background-color: rgb(255, 255, 255);
  box-shadow: 0px 0px 1px 2px var(--mainColor);
  transition: 0.3s;
  -moz-transition: 0.3s;
  -webkit-transition: 0.3s;
}

.littleClose:hover {
  background-color: var(--mainColor);
  color: white;
  transition: 0.3s;
  -moz-transition: 0.3s;
  -webkit-transition: 0.3s;
}

</style>